Jump to content

Geocoding using Google Maps


gerkintrigg

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/265192-geocoding-using-google-maps/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.