Domanda

What I want to do is to generate latitude & longitude given an address, so I thought Google geocoding API would be great.

I've tried everything and still it doesn't want to work. I am not an experienced web programmer, so any help will be great.

I've tried with XML and with JSON, from JavaScript and from ASP, and nothing. I can't see the xml / json object :(

This is the best I could do, with ASP:

<%
address=Request.QueryString("address")
url = "http://maps.googleapis.com/maps/api/geocode/json?address="
url = url + address + "&sensor=false"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""

data = xmlhttp.responseText
Response.write data
' Creating the XML object (New code added) :
set xml = xmlhttp.responseXML
Response.write xml.documentElement.selectSingleNode("result").text

set xmlhttp = nothing
%>

Here at least it seems I can obtain data from the server. However, I cannot convert the info in a JSON object (nor XML asking server to provide it in XML).

If somebody knows how to do it, with ASP or JavaScript, Json or XML, I'll be very thankful.

È stato utile?

Soluzione 2

Ok, after some more reasearch with a friend, we've at last done it:

In ASP, the key is playing with

selectSingleNode("name of your node")

childNodes(integer pointing to the node)

So you can select nodes inside nodes inside nodes etc.

Thus, after creating the object as said on the question, you just need to do:

set xml = xmlhttp.responseXML
Response.write xml.documentElement.selectSingleNode("result").selectSingleNode("geometry").selectSingleNode("location").text

For example, if you were looking for the lat & long.

Altri suggerimenti

Here's how I would do it in PHP, just translate to ASP and you're away!

$XML = file_get_contents("http://maps.google.com/maps/geo?q=$address&output=xml&oe=utf8&sensor=false&key=$mapskey");

if (preg_match('/<coordinates>([\d.-]*),([\d.-]*),0<\/coordinates>/', $XML, $matches)) {
    $longitude = $matches[1];
    $latitude = $matches[2];
}

The problem with your code is that you are requesting json the proper URL should be url = "http://maps.googleapis.com/maps/api/geocode/xml?address="

And Not

url = "http://maps.googleapis.com/maps/api/geocode/json?address=

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top