Reputation: 9327
How to get coordinates using javascript Google Maps JavaScript API v3 of the center of the currently viewed area on google maps? Thanks
Upvotes: 70
Views: 69152
Reputation: 1
This was a bug bearer for me. You have to create a pin element in the xml as such if you want a hoover over the map on centre.
//onMapReady
mMap = googleMap;
//In your listener/ screen code area
LatLng latlong = mMap.getCameraPosition().target;
HashMap<String, Object> map = new HashMap<>();
map.put("Latitude", latlong.latitude);
map.put("Longitude", latlong.longitude);
//push to your database
Upvotes: 0
Reputation: 2404
Updated 2018 The below codes are for Google Maps API for Android. In case anyone needs this Script:
double mylat = mGoogleMap.getCameraPosition().target.latitude;
double mylon = mGoogleMap.getCameraPosition().target.longitude;
Upvotes: 18