gerkintrigg Posted July 4, 2012 Share Posted July 4, 2012 Hi guys. I have this working already: http://truro.com/test.php It takes a hard-coded postcode variable and lets the buttons instantiate the centering of the map and placing the marker etc. My main problem is that the functionality needs to center the map and place the marker automatically on load. I'm not sure how to do that... I'll place the code if it'll help, but I don't quite know where to look. Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted July 4, 2012 Author Share Posted July 4, 2012 Hmm... i think I might have sorted it. The only issue now will be passing the variable to the javascript, but I have an idea. Quote Link to comment Share on other sites More sharing options...
haku Posted July 4, 2012 Share Posted July 4, 2012 You can set the center using this in the callback function to your geocoder request: geocoder.geocode(geocoderRequest, function(results, status) { var newLocation, lat, lng, center; switch(status) { case gm.GeocoderStatus.OK: // Center the map on the returned location newLocation = results[0].geometry.location; lat = newLocation.lat(); lng = newLocation.lng(); center = new gm.LatLng(lat, lng); map.setCenter(center); break; } }); If you need the marker, use can use the 'center' variable as the position of the marker. Note that 'map' is the google map which will need to be part of the scope of this function. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.