2012-08-11 70 views
1

可能重複:
How retrieve latitude and longitude via Google Maps API?由用戶從地圖中選擇位置獲得緯度和經度

我要地圖添加到我的網站,我鎮爲它的位置。它被用來列出我們網站上的商店。用戶需要在地圖中找到他們的商店位置。我們需要獲得他們的經緯度位置。是否有可能使用谷歌地圖API?在script標籤

<script type="text/javascript" src="http://www.google.com/jsapi?autoload={'modules':[{name:'maps',version:3,other_params:'sensor=false'}]}"></script> 

這:

+3

因此,SO確實是針對「爲什麼不做這項工作」這樣的具體問題,而不是「如果我做到了,它會工作嗎」?你至少應該先試一試,或者在你問到問題之前閱讀谷歌地圖的一個API。 – WhyNotHugo 2012-08-11 05:54:50

+0

看看這個:http://stackoverflow.com/questions/2770421/how-retrieve-latitude-and-longitude-via-google-maps-api#2770439 – ghbarratt 2012-08-11 05:55:26

+2

答案是肯定的,這是可能的。地圖上的點擊事件(或標記移動事件)可以生成緯度/經度座標。但是SO是針對*特定的*編碼問題的。你的代碼有哪些具體問題? – 2012-08-11 13:41:26

回答

1

一下添加到head

var geo; 
function init() { 
    var map_elem = document.getElementById('map-canvas'); 
    var map = new google.maps.Map(map_elem, { 
     center: new google.maps.LatLng(0, 174.8859710), 
     zoom: 2, 
     minZoom: 2, 
     maxZoom: 4, 
     mapTypeId: google.maps.MapTypeId.HYBRID 
    }); 
    geo = new google.maps.Geocoder(); 
    geo.geocode({ 
     address: 'New Zealand' 
    }, function(e) { 
     alert(e[0].geometry.location); 
    }); 
} 
google.maps.event.addDomListener(window, 'load', init); 

根據需要調整。

請參閱Geocoding Service - Google Maps JavaScript API v3 - Google Developers

+0

你也可以從'geometry'中獲得變量'viewport'和'bounds'。 – 2012-08-11 07:40:07

+0

我非常感謝大家支持我。我清楚地知道它是如何工作的。謝謝大家 。 。 。 – Anoop 2012-08-11 14:54:20