Jump to content

Recommended Posts

Hi there,

 

I am having a small problem getting php to work with google maps APIs. 

 

Basically, I have an API url where I pull down lat/long coordinates from for 10 houses and then I want these to map out on the google maps. So, I am not sure how to link the 2 together..

 

Here is what I have so far:

<?php
// Loading Domus API
$url_search = 'http://url/site/go/api/search';
$xml_search = @simplexml_load_file($url_search) or die ("no file loaded") ;
//Displaying latitude and longutude
$xml_search = json_decode($xml_search);
foreach($xml_search->property as $house) { 
    echo $lat = $house->address->latitude , $long = $house->address->longitude;
    };
?>

and JavaScript bit:

var locations = [ ];

var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 10,
  center: new google.maps.LatLng(-33.92, 151.25),
  mapTypeId: google.maps.MapTypeId.ROADMAP
});

var infowindow = new google.maps.InfoWindow();

var marker, i;

for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map
  });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
  })(marker, i));
}

Many thanks

 

Link to comment
https://forums.phpfreaks.com/topic/285348-google-maps-api-with-php/
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.