如何在android应用中显示位置的位置 [英] How to display a location of a place in android app

查看:137
本文介绍了如何在android应用中显示位置的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种显示android应用程序中位置的位置的方法.我具有存储在MySQL数据库中的位置的经度和纬度坐标,现在我想检索它们(经度和纬度)并在应用程序中显示确切位置.谢谢

I am looking for a way to display a location of a place inside an android application. I have the longitude and Latitude coordinates of the place stored inside a MySQL database, now I want to retrieve them (Longitude and latitude)and display the exact location in the application. thanks

推荐答案

我假设您要在带有标记的地图视图上使用它.

I am assuming you want it on a map view with a marker.

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    class="com.google.android.gms.maps.MapFragment" />

这应该添加到您希望地图参与的活动的xml文件中. 然后在您的活动中,

This should be added to you xml file of the activity you want the Map to be in. Then in your activity,

GoogleMap googleMap;
MapFragment mapFragment;

在您的onCreate中将其初始化;

Initialize this in you onCreate;

mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

,然后创建替代方法onMapReady()

@Override
public void onMapReady(GoogleMap gMap) {
    googleMap = gMap;
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    try {
        googleMap.setMyLocationEnabled(true);
    } catch (SecurityException se) {

    }

    //Edit the following as per you needs
    googleMap.setTrafficEnabled(true);
    googleMap.setIndoorEnabled(true);
    googleMap.setBuildingsEnabled(true);
    googleMap.getUiSettings().setZoomControlsEnabled(true);
    //

    LatLng placeLocation = new LatLng(***YOUR LAT***, ***YOUR LNG***); //Make them global
    Marker placeMarker = googleMap.addMarker(new MarkerOptions().position(placeLocation)
                  .title(***NAME OF PLACE HERE***));
    googleMap.moveCamera(CameraUpdateFactory.newLatLng(placeLocation));
    googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 1000, null);
}

我认为这应该给您您想要的.如果您还有其他需要,请发表评论.

I think that should give you what you want. Comment if you need anything else.

这篇关于如何在android应用中显示位置的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆