按位置标记位置google maps v3 [英] Mark a location by location google maps v3

查看:95
本文介绍了按位置标记位置google maps v3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提供一个功能,例如用户将提供城市,州和国家.然后,我的目的是在Google地图上标记用户提供的位置.

I want to provide a feature like user will provide a city,state and country. Then my aim is to mark the location provided by the user on the google maps.

我的代码是:

<!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

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

Is there something wrong i am doing? Or any other way to mark the location by providing location.

谢谢.

推荐答案

我得到了答案

<!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>

这篇关于按位置标记位置google maps v3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆