-1

I just wondered if anyone knew of a simple script available that will do the following:

Show Google map location of a particular vendor by getting its name from URL. Like we see in various listing websites like Justdial, IndiaMart, Zomato and a lot more. More clearly if my URL is

 www.example.com/list.php?city=Delhi

It will show Delhi on google map embed on my list.php web page.

Does anyone know if something like this already exists in PHP?

Thanks in advance.

Ashish
  • 303
  • 5
  • 22
  • Possible duplicate of [How to display only one country or a specific area in Google maps using the api?](http://stackoverflow.com/questions/717019/how-to-display-only-one-country-or-a-specific-area-in-google-maps-using-the-api) – N3sh Mar 01 '17 at 10:55
  • @N3sh That question is far away from my question. In that question he wants to show a fixed country i.e. US. But my question is i want to show that city in map which is in the URL. If URL is www.example.com/list.php?city=Delhi then Delhi if its Mumbai, Bangluru, Chennai or whatever, show that city not Delhi. – Ashish Mar 02 '17 at 06:30

1 Answers1

3

This will help you.

Html Part.

<div id="map" style="width:100%; height:500px;"></div>

Javascript:

function initMap() {
    var latitude = your latitude;
    var longitude = Your longitude;

    var myLatlng = {lat: parseFloat(latitude), lng: parseFloat(longitude)};
    var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 12,
        center: myLatlng
    });

    var address = Address;

    var infowindow = new google.maps.InfoWindow({
        content: address
    });

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Click to zoom'
    });

    marker.addListener('click', function () {
        infowindow.open(map, marker);

    });

}

And finally you have to include map library.

<script async defer
    src="https://maps.googleapis.com/maps/api/js?key=Google key&callback=initMap">
</script>
Ajay Korat
  • 716
  • 4
  • 14
  • An error is there in script and i am failed to find..Can you please recheck again. DW showing error at second line of script....var latitude= Your latitude;....And do i need to change address to city.... – Ashish Mar 01 '17 at 08:45
  • DId you add your latitude ```ex. 2.5649852``` something instead ```Your latitude```.? – Ajay Korat Mar 01 '17 at 08:47
  • But this is not what i am looking for....I want to know that Is it compulsory to know the latitude and longitude of a location to embed its Google map on my webpage ??? – Ashish Mar 01 '17 at 08:52
  • That's fine, Great :) – Ajay Korat Mar 01 '17 at 08:52
  • If you have to show location marker on the map then ```lat, lng``` is compulsory without it how do you identify location.? – Ajay Korat Mar 01 '17 at 08:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/136936/discussion-between-ajay-korat-and-ashish). – Ajay Korat Mar 01 '17 at 08:54