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
https://forums.phpfreaks.com/topic/214310-google-maps/
Share on other sites

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.