google-maps - 如何使用谷歌地图将地址地理编码为纬度/经度

标签 google-maps google-maps-api-3 google-maps-markers

我希望能够在谷歌地图上绘制几家公司,并了解我需要对这些公司进行地理编码。

我在 map 上的多个标记下方也有代码。

如何对多个公司地址进行地理编码(使用以下地址作为第一个示例)并将其合并到我拥有的当前代码中?

我真的需要别人的帮助,因为我无法理解 Google 文档以及将其与我已有的文档结合起来。

最佳答案

您可以使用 google's geocoding获取您的邮政编码的坐标

编辑:我真的不喜欢你这样改变问题的意义,但是好的。请尝试这样(未测试):

// Creating an array that will contain the coordinates 
// for New York, San Francisco, and Seattle
var places = [];

// Adding a LatLng object for each city
//places.push(new google.maps.LatLng(40.756, -73.986));
//places.push(new google.maps.LatLng(37.775, -122.419));
//places.push(new google.maps.LatLng(47.620, -122.347));
//places.push(new google.maps.LatLng(-22.933, -43.184));
var result;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://maps.googleapis.com/maps/api/geocode/json?address=your+code&sensor=false",true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
       result = eval('(' + xmlhttp.responseText + ')');
if (result.status == "OK") {
var location = new google.maps.LatLng(result.results[0].geometry.location.lat, result.results[0].geometry.location.lng);
places.push(location);

这应该可以工作,尽管可能有一些小错误。

EDIT2:我刚刚找到 simpler solution :

// Creating an array that will contain the coordinates 
// for New York, San Francisco, and Seattle
var places = [];

// Adding a LatLng object for each city
//places.push(new google.maps.LatLng(40.756, -73.986));
//places.push(new google.maps.LatLng(37.775, -122.419));
//places.push(new google.maps.LatLng(47.620, -122.347));
//places.push(new google.maps.LatLng(-22.933, -43.184));
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': "your+code"}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    //var marker = new google.maps.Marker({
        //map: map,
        //position: results[0].geometry.location
    //});
    places.push(results[0].geometry.location);
  } else {
    alert("Geocode was not successful for the following reason: " + status);
  }
});

关于google-maps - 如何使用谷歌地图将地址地理编码为纬度/经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7499862/

相关文章:

javascript - 隐藏部分 map

javascript - map 标记未呈现 - Phonegap 中的 Google Maps Javascript API v3

javascript - 谷歌地图 APIs v3 和 IE 6

javascript - 谷歌地图 : How to add HTML elements to specific coordinates?

java - Android Maps API 版本 1 到版本 2 的迁移

java - 如何在android Canvas 中绘制一个实心三角形?

mysql - 哪个 FOSS RDBMS 用于地理空间数据?

php - 如何使用 jquery-ui-map 在谷歌地图上添加标记

reactjs - google-map-react 可拖动标记 - onChildMouseMove 不适用于移动设备

Android:在将标记保持在中心的同时拖动 map