How to use new Google Maps coordinates (GMS) with LatLng? - javascript

I'm using a Google Maps object on my website to display different locations I've been to. I always used the coordinates (GGG) from the old Google Maps to set a new marker to my map. But with the new Google Maps I only get GMS format.
Before: 51.055207,10.524902
After: 51° 4.193', 8° 41.807'
My problem is, that I'm not able to use google.maps.LatLng to set a marker position anymore. If I'm typing in the new format, my map crashes and no marker is shown.
Is there another method I could use? Or do I have to convert the positions to GGG format?

Use the decimal format that you used to use. The API has not changed with the visual refresh of the maps so everything should work as usual. If that's not working, please provide your code so we can help troubleshoot.

Related

Leaflet Map and Layer don't move at the same time when zooming in / out

I have a small issue in the application I am building currently, and I can't figure out what's the problem.
I am using leaflet for displaying the map, with a Google Maps layer as a map.
My problem is that when I am zooming in or out of the map, the actual maps move directly but it takes almost a second before the markers layer gets updated too.
You can reproduce my problem easily on this test server, by choosing on of the points of interest, and zooming in or out when the points are displayed.
I haven't found any reference of this problem on the internet so far. Do you have any idea where this could come from ?
Thanks!
This is using a Google Maps layer, which means it wraps the Google Maps API. Since the Google Maps API zooms at a different speed than Leaflet, you see this effect.
There's no quick fix here: it's just not a very good idea to use the Google Maps API within Leaflet, technically or legally. Either use Leaflet with tiles that can be used directly with it - OSM, MapQuest, Stamen, Mapbox - or use the Google Maps API.

CFGMap Google map API V3 always center map on long/lat

I'm using CFGMap solution to place markers on a google map (API V3) but I want the map to always be centered on a certain long/latitude. Right now it seems to center on the last marker placed on the map so if the majority are where I want the long/lat centered then one random marker will take view miles away.
Any help on this is appreciated.
Thanks!
CFGMap is infuriating for it's lack of documentation. I don't use it myself; I only tried to track down something that might help you. On the face of it, it appears only to take a tiny subset of the full API functionality and doesn't offer much else.
From what I can glean from the testmap.js found here, it appears that you can only center the map on an existing marker in your locations array (see line 616 of the github file).
_cfGMapObj.resetCenterToLoc(index);
So, for example, in the source of the example is the line:
_cfGMapObj.resetCenterToLoc($('#locID','#printLink').val());
which grabs the number from the value of the current option in the select at the top of the page.
Now, if you chose instead to knock CFGMap on the head you could employ the Map API fully and set the center of the map using the setCenter method of the API.:
map.setCenter(new google.maps.LatLng(lat, lng));
e.g.
map.setCenter(new google.maps.LatLng(57.4419, -121.1419));
which in my mind is much easier. Plus, if you decided to do this, there are tons more articles on the API on StackOverflow than there are on CFGMap. YMMV.

How to prompt user for place using Google Maps in javascript?

I am new to Google Maps and still new to Javascript. I need to have a user select a location on a map (using Google Map) and retrieve the corresponding town, country, latitude and longitude. If timezone is available too, that would be great.
I can't find an operational code example. Does anyone have one to share? Thanks.
The sample code provided by Google at http://code.google.com/apis/maps/documentation/javascript/examples/event-arguments.html gets a LatLng from a mouse click and puts a marker on a map. (Just view the source code to see the sample code.)
The sample code provided by Google at http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-reverse.html takes a latitude and longitude and determines the location via reverse geocoding. (Again, view source code to see the sample.)
Sounds like your functionality is basically parts of each of those samples and fusing them.
You might want to check out the Events documentation and the Reverse Geocoding documentation if you run into any problems (or even if you don't).

Highlighting custom locations on map

I would like to do something like what is shown in the screenshot - http://themanyfacesof.com/wp-content/uploads/2010/03/map.png
I want to be able to highlight certain areas on a map using PHP as a server side technology and jQuery(preferable) on client side with some tooltip functionality. Is there anything available or any idea how this could be achieved with the complexity involved?
Completely client-side solution: http://jvectormap.owl-hollow.net/
Look into using Google Maps for this. You can overlay lines and polygons which effectively means you can do anything - for example Loughbrough University does this.
A good way to start is to
Log in to Google
Go to Google Maps, then to my maps and create a new map
Draw polygons and line using the tools provided
Right click and copy the link for Google Earth, visit this link but change the output to KML output=kml. KML is just like XML
You now have a file with the exported polygons and lines that you drew. You can then re-draw these onto a Google Map programmatically
I did this the other day to get some rather complex polygons drawn onto a map without having to trial and error the latitude and longitude coordinates for them.
Hope that helps.

Google Maps v3 panTo() from getCenter() lat lng doesn't go to same location

I'm using getCenter() to use the lat lng in a url so users can share / bookmark a location on Google Maps. I then use panTo() to try and jump back to the same location. Though it always jumps back to approximately the same location it's never exactly the same view.
I've thought about using setCenter() instead of panTo() but this can mess up the referencing calculation for the custom map layer I'm displaying. Depends where the center happens to be.
To see the problem in action you can go to http://www.topomap.co.nz/ and use the "Share" tab to get a url generated from getCenter(). Using the url you'll notice they show slightly different centers.
Please note that I'm currently using latLng.toUrlValue() which reduces some of the accuracy, but you can manually tweak the url from the individual lat long given in the "Share" tab and you'll still see the same problem.
Any ideas what might be going on?
You may get the bounds of the map using map.getBounds() before transition and then when you need to get back to this view use
fitBounds(bounds:LatLngBounds)
or
panToBounds(latLngBounds:LatLngBounds)
Don't know if it will work, give it a try...
Found here.
http://code.google.com/apis/maps/documentation/javascript/reference.html#Map
Seems panTo() is no substitute for setCenter(). I just have to code around my Prime Meridian issue and use setCenter() instead.

Categories

Resources