[英]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.