简体   繁体   English

如何在Google Map v2中获取标记的经度和纬度值

[英]How to get the longitude and latitude value of the marker in google map v2

I am working in google map v2. 我正在使用Google Map v2。 I just added one marker on the map. 我只是在地图上添加了一个标记。 But I am not being able to get location from the marker. 但是我无法从标记中获取位置。 I have search a lot in google but didn't get proper answer. 我在Google中搜索了很多,但没有得到正确的答案。 I just want to toast the longitude and latitude value of the marker. 我只想敬酒标记的经度和纬度值。 Can anyone suggest me anything? 有人可以建议我什么吗?

My code: 我的代码:

double mylongitudey,mylatitudey;
String latilongi;
ImageView iv;
Button manual,proceed;

GoogleMap map;
LatLng mylat ;

String latlong;
Marker mymarker,marker;
boolean markerclicked;
double mylatitudeyd,mylongitudeyd;
String addstringaa;


@Override
protected void onCreate(Bundle savedInstanceState) {
 LocationManager lm;
  lm= (LocationManager) getSystemService(Context.LOCATION_SERVICE);

  Toast.makeText(this,"Please select the destination by long click", Toast.LENGTH_LONG).show();

  LatLng mylat;

  final GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
  map.setOnMarkerDragListener(this);
  map.setTrafficEnabled(true);
  map.setMyLocationEnabled(true);
  map.setOnMarkerDragListener(this);


  map.setOnMyLocationButtonClickListener(this);

  map.animateCamera(CameraUpdateFactory.zoomTo(15));
 // map.setOnMyLocationButtonClickListener(this);


  map.moveCamera(CameraUpdateFactory.newLatLngZoom(mylat, 13));
 map.addMarker(new MarkerOptions().position(mylat).title("You are Here"));

 markerclicked=false;
  //onMyLocationButtonClick();
  map.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

    @Override
    public void onMapLongClick(LatLng arg0) {
        // TODO Auto-generated method stub


        if(markerclicked==false)
        {
         mymarker = map.addMarker(new MarkerOptions().position(arg0).title("Your Destination").draggable(true));
         markerclicked=true;
    }else{

         Toast.makeText(getApplicationContext(), "Marker Aready Set..!", Toast.LENGTH_LONG).show();

    }

    }
});


  map.setOnMyLocationChangeListener(new GoogleMap.OnMyLocationChangeListener() {
    LatLng mylatlong;
    @Override
    public void onMyLocationChange(Location arg0) {

        // TODO Auto-generated method stub
        mylongitudey = arg0.getLongitude();
        mylatitudey = arg0.getLatitude();
        mylatlong = new LatLng(arg0.getLatitude(), arg0.getLongitude());
        //sourcepoint=String.format(" ",mylat);
        marker= map.addMarker(new MarkerOptions().position(mylatlong).title("YOur Destination"));
//  map.moveCamera(CameraUpdateFactory.newLatLngZoom(mylat,1));
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(mylatlong, 14));


    }
});

Calling marker.getPosition() will return a LatLng object which stores latitude and longitude. 调用marker.getPosition()将返回一个LatLng对象,该对象存储纬度和经度。

Marker marker = <your initialization>;
LatLng latLng = marker.getPosition();
double latitude = latLng.latitude;
double longitude = latLng.longitude;
try {
            List<Address> detail = gcd.getFromLocation(location.getLatitude(),
                    location.getLongitude(), 1);
            cityName = detail.get(0).getAddressLine(1);

        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

try 尝试

latitude = detail.get(0).getLatitude();
Log.d("location"+marker.getPosition().longitude+" "+marker.getPosition().latitude);

也许这会有所帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当网络服务中的经度和纬度发生变化时,如何在Google地图中移动标记? - How to move the marker in Google map when the latitude and longitude changes in webservices? 如何在Android中从Google Map v2清除圆圈和标记 - How to clear the circle and marker from the Google Map v2 in android 如何从谷歌地图 URL 获取纬度经度 - How to get latitude longitude from google map URL 如何在android studio中的谷歌地图上获取选定位置的纬度和经度 - How to get latitude and longitude of select location on google map in android studio 如何在Android中获取谷歌地图蓝点的经度和纬度 - how to get the google map blue point latitude and longitude in android 当我从短信中接收经度和纬度时,如何在Google地图中添加标记 - How to add marker in google map when i recieve longitude and latitude from sms 如何从我在地图上设置的标记保存经度和纬度 - How to save longitude and latitude from the marker i set on the map 如何从地图中的标记获取纬度和经度 - How to get latitude and longitude from a mark in the map 转换谷歌地图中的纬度和经度? - converting latitude and longitude in google map? 在Android中使用Google Map V2在触摸的位置添加标记 - Add marker on touched location using google map v2 in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM