【问题标题】:Mark a location by location google maps v3按位置标记位置 google maps v3
【发布时间】:2013-01-08 07:28:33
【问题描述】:

我想提供一个功能,比如用户将提供城市、州和国家/地区。然后我的目标是在谷歌地图上标记用户提供的位置。

我的代码是:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
    <meta name="dcterms.created" content="Tue, 08 Jan 2013 05:31:17 GMT">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <title></title>
    <?php
// get and breakdown the results then store them in $var's
$Address = "99999 parkplace, new york, NY";
$urladdress = urlencode($Address);
$Base_url = "http://maps.google.com/maps/geo?q=";
$urlParts = "&output=xml";
$urlrequest = $Base_url . $urladdress . $urlParts;
$xml = simplexml_load_file($urlrequest);
$num = "0";
$value=$xml->Response->Placemark;
    $GeoFindAdd{$num} = $value->address;
    $GeoFindCords{$num} = $value->Point->coordinates;
?>
    <script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
    <script>
        var myCenter=new google.maps.LatLng(<?php echo $GeoFindCords{$num}; ?>);

function initialize()
{
var mapProp = {
  center:myCenter,
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

var marker=new google.maps.Marker({
  position:myCenter,
  });

marker.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
<div id="googleMap" style="width:500px;height:380px;"></div>
  </body>
</html>

代码的输出是

http://wfs-01.wapka.mobi/300030/300030787_6850a0ae9a.png

我做错了什么吗?或通过提供位置来标记位置的任何其他方式。

谢谢。

【问题讨论】:

    标签: google-maps location


    【解决方案1】:

    我得到了答案

    <!DOCTYPE html>
    
    <html lang="en">
    
    <head>
    
    <meta charset="utf-8">
    
    <meta name="generator" content="CoffeeCup HTML Editor (www.coffeecup.com)">
    
    <meta name="dcterms.created" content="Tue, 08 Jan 2013 05:31:17 GMT">
        <meta name="description" content="">
    
    <meta name="keywords" content="">
    
    <title></title>
    
    <script
    src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
    </script>
    
    <script>
    
    var geocoder, map;
    
    function initialize() {
    
    geocoder = new google.maps.Geocoder();
    
    var latlng = new google.maps.LatLng(10, 10);
    
    var myOptions = {
        zoom: 0,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
    
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    codeAddress();
    
    }
    
    
    function codeAddress() {
    
    var address = "Kottayam, Kerala";
    
    geocoder.geocode( { 'address': address}, 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
          });
    
    } 
    else {
    
    alert("Geocode was not successful for the following reason: " + status);
        }
      });
    }
    
    </script>
    
    </head>
    
    <body onload="initialize()">
     <div id="map_canvas" style="width: 320px; height: 480px;"></div>
    
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2012-01-28
      • 1970-01-01
      • 2012-01-06
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2013-11-08
      相关资源
      最近更新 更多