Search the Community
Showing results for tags 'google-maps'.
-
I need a map which locates all the stores addresses(Less than 10). Those address must be retreived from the database. But the database don't contain any lat or long field. Therefore geocoding an address into their corresponding lat and long coordinates must be done and appropriate markers must be placed. The code which I have at the moment is as follows:- <?php require_once '../model/stores.php'; $obj=new Stores(); $result=$obj->getStores(); $new_array = array(); while($row=mysql_fetch_assoc($result)){ $new_array[] = $row['stores_address']; } $add_js = json_encode( $new_array ); ?> <html> <head> <style> #map_canvas { width: 500px; height: 500px; } </style> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script> $(document).ready(function () { var map; var elevator; var myOptions = { zoom: 1, center: new google.maps.LatLng(0, 0), mapTypeId: 'terrain' }; map = new google.maps.Map($('#map_canvas')[0], myOptions); //var addresses = ['Norway', 'Africa', 'Asia','North America','South America']; var addresses = <?php echo $add_js ?>;; for (var x = 0; x < addresses.length; x++) { $.getJSON('http://maps.googleapis.com/maps/api/geocode/json? address=' +addresses[x]+'&sensor=false', null, function (data) { var p = data.results[0].geometry.location var latlng = new google.maps.LatLng(p.lat, p.lng); new google.maps.Marker({ position: latlng, map: map }); }); } }); </script> </head> <body> <div id="map_canvas"></div> </body> </html> I have looked on various forums and other web resources but no use as none of them worked out for me...Hope any genius would help me to solve the problem.
- 1 reply
-
- php
- google-maps
-
(and 2 more)
Tagged with:
-
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
-
- php
- google-maps
-
(and 2 more)
Tagged with: