-1

Hi Guys i am using the following code to load the map of a location

var map;
    function initialize() {
      var mapOptions = {
        zoom: 8,
        center: new google.maps.LatLng(-34.397, 150.644)
      };
      map = new google.maps.Map(document.getElementById('map-canvas'),
          mapOptions);
    }

I want to use location as string to draw the map something like this

google.maps.Location(-34.397, 150.644)

If it is possible.

Tauseef
  • 369
  • 3
  • 15
Tausif Anwar
  • 1,237
  • 1
  • 10
  • 21
  • https://developers.google.com/maps/documentation/javascript/geocoding – MrUpsidown Apr 26 '15 at 12:41
  • possible duplicate of [Using Address Instead Of Longitude And Latitude With Google Maps API](http://stackoverflow.com/questions/15925980/using-address-instead-of-longitude-and-latitude-with-google-maps-api) – geocodezip Apr 26 '15 at 14:24

1 Answers1

0

I guess you want to use latitude and longitude to get name of location, so you have to use the Reverse Geocoding service from google map api . This is the function that you need :

function codeLatLng() {
var input = document.getElementById('latlng').value;
var latlngStr = input.split(',', 2);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
  if (results[1]) {
    map.setCenter(latlng);
    map.setZoom(11);
if(marker){
 marker.setPosition(latlng); 
}  
else {
      marker = new google.maps.Marker({
        position: latlng,
        map: map
     });
}   
 // adr is the latitude longitude place name after geocoding
    adr =  results[1].formatted_address;
    document.getElementById("adresse").value = adr ;


  } else {
    alert('No results found');
  }
 } else {
  alert('Geocoder failed due to: ' + status);
 }
 });
 }