2011-08-21 6 views
13

どのように座標を入力してGoogleマップに位置情報を表示させることができますか?これには、JavaScriptを介して行われるすべての(すなわち:ユーザインタフェースなし)すべてのヘルプを表示位置緯度/経度座標を使用する - Googleマップ

+0

私は同じことを求めてきましたし、彼らは答えた - > http://stackoverflow.com/questions/ 8766116/how-can-i-get-xy-number-at-click-on-google-maps – SamekaTV

+0

@SamekaTV - このリンクは反対の目標です(地図をクリックし、経度/緯度を戻しています)。この質問は、その地点の地図をどのように表示するかについては、既知の経度/緯度が与えられています。 (または、おそらくshahmeerは、すでに開いている地図上のその場所にマーカーを表示する方法の関連する質問をしていた) – ToolmakerSteve

+0

詳細なブログ:http://sforsuresh.in/display-google-map-locations- /緯度経度を使用する/ –

答えて

11

注すでに緯度/経度がある場合は、Alteveer’s answerを参照してください。

緯度経度を取得するには、ジオロケーションサービスを使用する必要があります。 Googleマップは、内蔵のものを持っている: http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding

ここでそれを使用する方法の例です:

<!-- Placeholder for the Google Map --> 
<div id="map" style="height: 512px;"> 
    <noscript> 
    <!-- http://code.google.com/apis/maps/documentation/staticmaps/ --> 
    <img src="http://maps.google.com/maps/api/staticmap?center=1%20infinite%20loop%20cupertino%20ca%2095014&amp;zoom=16&amp;size=512x512&amp;maptype=roadmap&amp;sensor=false" /> 
    </noscript> 
</div> 

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript"> 

// Define the address we want to map. 
var address = "1 infinite loop cupertino ca 95014"; 

// Create a new Geocoder 
var geocoder = new google.maps.Geocoder(); 

// Locate the address using the Geocoder. 
geocoder.geocode({ "address": address }, function(results, status) { 

    // If the Geocoding was successful 
    if (status == google.maps.GeocoderStatus.OK) { 

    // Create a Google Map at the latitude/longitude returned by the Geocoder. 
    var myOptions = { 
     zoom: 16, 
     center: results[0].geometry.location, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map"), myOptions); 

    // Add a marker at the address. 
    var marker = new google.maps.Marker({ 
     map: map, 
     position: results[0].geometry.location 
    }); 

    } else { 
    try { 
     console.error("Geocode was not successful for the following reason: " + status); 
    } catch(e) {} 
    } 
}); 
</script> 
+1

質問されたものとは異なる質問。尋ねられる質問は:LATITUDE/LONGITUDEを与え、地図を表示する、または地図上にマーカーを表示することです。この回答は:アドレスが与えられた場合、地図上にマーカーを表示します。 **既に緯度/経度**がある場合は、 '//アドレスのマーカーを追加する.'の行を参照してマーカーを表示してください。新しい地図を開く場合は、[Alteveer's answer](https://stackoverflow.com/a/7135770/199364)を参照してください。 – ToolmakerSteve

+0

それは大きなポイントです、スティーブ。 (おっと!)私はこの回答にメモを追加しました。 – Jim

関連する問題