Jump to content

google maps


Yawa

Recommended Posts

Hello - I want's to implement Google maps on a website.

It's an advertising- and marketing -site for businesses and consumers in Norway and I'm trying to add a map to their profile and Ads.

 

I'm wondering on two things here: #1 how to change a markers location and save it - and #2 how to show multiple markers based on results from a database.

 

But one thing at a time...

 

When a business, or a consumer, register a profile and has entered an address, a suggestion is made based on the stored address. If the suggestion is wrong - the user can moved the icon to the correct location and save it (or update it).

 

I'm thinking the solution here is to fetch the latitude/longitude somehow, and store it in a database. When a user moves/drags the icon to another location - it stores the values into two hidden <input>-fields and uploads/updates it with PHP when submitted by user.

 

 

Here is my .JS-script I'm using to show the map in each profile at the moment:

var geocoder;
var map;

function initialize() 
{
  geocoder = new google.maps.Geocoder();
  var myOptions = { zoom: 12, navigationControl: true, scaleControl: true, mapTypeControl: false, mapTypeId: google.maps.MapTypeId.ROADMAP }
  map = new google.maps.Map(document.getElementById('businessLocation'), myOptions);
  codeAddress();
}

function codeAddress() 
{
  var address = document.getElementById('address').value;
  geocoder.geocode ({ 'address': address }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK)
    {
      map.setCenter(results[0].geometry.location);
      var marker = new google.maps.Marker({ map: map, position: results[0].geometry.location });
    }
    else { alert("Geocode was not successful for the following reason: " + status); }
  });
}

And here is the 'address' <input>-field:

<input id="address" name="address" type="hidden" value="'.$get['adressStreet'].', '.$get['adressCode'].' '.$get['adressCity'].', Norway" size="32" />

As you can se, I'm using Geocode to convert a human readable address (that is stored in a database) into lati-/longitude, to center the view and place the marker.

 

 

What I'm basically asking for here is how to store a markers location, after it has been dragged, so everybody sees the correct location?

 

Is there someone who knows about this stuff an can share some knowledge?

 

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.