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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.